/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import View.*;
import DAO.*;
import TO.BookTO;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author admin-pc
 */
public class BookController {

    private BookView view;
    private BookTO model;

    BookDAO daof = DAOFactory.getInstance().getBookDAO();

    public BookController(BookTO model) {
        this.model = model;
        view = new BookView(model, model, this);
    }

    public void bookAdd(String title, String status) {
        daof.add(new BookTO(title, status));

    }

    public void bookDelete(int id) {
        daof.delete(id);
    }

    public void bookUpdateStatus(int id, String status) {
        daof.updateStatus(new BookTO(id, status));
    }

    public void bookUpdateTittle(int id, String tittle) {
        daof.updateTittle(new BookTO(id, tittle));
    }

    public void bookFindByAuth(String authName) {
        daof.findByAuth(authName);
    }

    public void bookSelectAll() {
        List list = daof.findAll();
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            BookTO book = (BookTO) iterator.next();
            System.out.print("ID Книги: " + book.getBookId() + " " + "\tНазвание книги: " + book.getBookTitle().trim() + "\tСтатус: " + book.getBookStatus().trim() + "\n");
        }
    }

}
